#!/usr/bin/env python
# coding=utf-8

"""
@author: yaqiwe
@contact: 15338230927@163.com
@file: AmazonSearchTest.py
@date: 2020/10/28 22:18
@desc: 测试AmazonSearch类
"""
from service.AmazonSearch import AmazonSearch


class AmazonSearchTest:

    def searchInfoTest(self):
        a = AmazonSearch()
        res = a.searchInfo('sock', 1500)
        with open('./searchInfoTest.html', 'w', encoding='utf8') as f:
            f.write(res.text)

    def getShopUrlListTest(self):
        a = AmazonSearch()
        res = a.searchInfo('sock', 1)
        urllist = a.getShopUrlList(res.text.encode('utf8'))
        for url in urllist:
            print(url)
    def isCurrentlyUnavailableTest(self):
        a = AmazonSearch()
        urlList = ['https://www.amazon.co.uk/Disney-Womens-Casual-Sock-Pack/dp/B07Y5ZYSV3',
                   'https://www.amazon.co.uk/Kensington%C2%AE-ULTRALITE-Athletic-Training-Triathlon/dp/B01LXY958T/ref=sr_1_6?dchild=1&keywords=socks&qid=1603895325&sr=8-6',
                   'https://www.amazon.co.uk/under-armour-heatgear-socks-black/dp/B07R1ZPYQD/ref=sr_1_16?dchild=1&keywords=sock&qid=1603896453&sr=8-16',
                   'https://www.amazon.co.uk/Horizon-Coolmax-Trekker-Mens-Socks/dp/B00303H3KE?th=1&psc=1',
                   'https://www.amazon.co.uk/Non-slip-Thermal-Leopard-Thickening-Non-falling/dp/B08KDV6YJV/ref=sr_1_61?dchild=1&keywords=sock&qid=1603899708&sr=8-61']
        list = a.isCurrentlyUnavailable(urlList)
        for url in list:
            print('通过测试url:'+url)
if __name__ == '__main__':
    # AmazonSearchTest().searchInfoTest()
    AmazonSearchTest().getShopUrlListTest()
    # AmazonSearchTest().isCurrentlyUnavailableTest()
